package com.jevons.muffin.event;

/**
 * Copyright 2020 JxGIS
 *
 * @file BaseEvent
 * @auth linaisheng
 * Created on 2021/6/29.
 * Description：
 * Used as a wrapper for data that is exposed via a LiveData that represents an event.
 */
public class BaseEvent<T> {

    public static final int EVENT_NONE = 0;
    public static final int EVENT_SUCCESS = 1;
    public static final int EVENT_ERROR = 2;


    private int mFlag;
    private T mContent;

    private boolean hasBeenHandled = false;

    public BaseEvent(int flag) {
        mFlag = flag;
        mContent = null;
    }

    public BaseEvent(T content) {
        mFlag = 0;
        mContent = content;
    }

    public BaseEvent(int flag, T content) {
        mFlag = flag;
        mContent = content;
    }

    public int getFlag() {
        return mFlag;
    }

    public T getContentIfNotHandled() {
        if (hasBeenHandled) {
            return null;
        } else {
            hasBeenHandled = true;
            return mContent;
        }
    }

    public T getContent() {
        return mContent;
    }



    public boolean hasBeenHandled() {
        return hasBeenHandled;
    }

}
